Clip
逐元素将输入张量 src 的值裁剪到指定的最小值 min 和最大值 max 范围内。
\[\text{dst}_i = \max(\min, \min(\text{src}_i, \max))\]
- 输入:
src - 输入张量的数据地址。
length - 输入张量的总元素数量。
min - 裁剪范围的最小值。
max - 裁剪范围的最大值。
core_mask - 核掩码。
- 输出:
dst - 输出张量的数据地址,其大小与`src`相同。
- 支持平台:
FT78NEMT7004
备注
FT78NE 支持int8, int16, int32, fp32, fp64
MT7004 支持int16, int32, fp16, fp32
共享存储版本:
-
void i8_clip_s(int8_t *src, int8_t *dst, int length, int8_t min, int8_t max, int core_mask)
-
void i16_clip_s(int16_t *src, int16_t *dst, int length, int16_t min, int16_t max, int core_mask)
-
void i32_clip_s(int32_t *src, int32_t *dst, int length, int32_t min, int32_t max, int core_mask)
-
void fp_clip_s(float *src, float *dst, int length, float min, float max, int core_mask)
-
void hp_clip_s(half *src, half *dst, int length, half min, half max, int core_mask)
-
void dp_clip_s(double *src, double *dst, int length, double min, double max, int core_mask)
C调用示例:
1//FT78NE示例
2#include <stdio.h>
3#include <clip.h>
4int main(int argc, char* argv[]) {
5 float *src = (float *)0xA0000000; // src 在DDR空间
6 float *dst = (float *)0xB0000000; // dst
7
8 int length = 4096;
9 float min = 0.0f;
10 float max = 6.0f; // 例如ReLU6的裁剪范围
11 int core_mask = 0xff;
12
13 fp_clip_s(src, dst, length, min, max, core_mask);
14 return 0;
15}
私有存储版本:
-
void i8_clip_p(int8_t *src, int8_t *dst, int length, int8_t min, int8_t max)
-
void i16_clip_p(int16_t *src, int16_t *dst, int length, int16_t min, int16_t max)
-
void i32_clip_p(int32_t *src, int32_t *dst, int length, int32_t min, int32_t max)
-
void fp_clip_p(float *src, float *dst, int length, float min, float max)
-
void hp_clip_p(half *src, half *dst, int length, half min, half max)
-
void dp_clip_p(double *src, double *dst, int length, double min, double max)
C调用示例:
1//FT78NE示例
2#include <stdio.h>
3#include <clip.h>
4int main(int argc, char* argv[]) {
5 float *src = (float *)0x10000000; // src 在L2空间
6 float *dst = (float *)0x11000000; // dst
7
8 int length = 1024;
9 float min = -1.0f;
10 float max = 1.0f;
11
12 fp_clip_p(src, dst, length, min, max);
13 return 0;
14}